package com.example.demo.controller;

import com.example.demo.service.WorkflowService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Coze聊天控制器
 * 提供聊天和工作流相关的API接口
 */
@RestController
@RequestMapping("/api/coze")
public class WorkflowController {

    private final WorkflowService workflowService;

    public WorkflowController(WorkflowService workflowService) {
        this.workflowService = workflowService;
    }

    /**
     * 运行工作流接口
     *
     * @param request 包含工作流ID和参数的请求
     * @return 工作流运行结果
     */
    @PostMapping("/workflow/run")
    public String runWorkflow(@RequestBody WorkflowRequest request) {
        return workflowService.runWorkflow(request.getWorkflowID(), request.getParameters());
    }

    /**
     * 流式运行工作流接口
     *
     * @param request 包含工作流ID和参数的请求
     * @return 流式工作流运行结果
     */
    @PostMapping("/workflow/stream")
    public String streamWorkflow(@RequestBody WorkflowRequest request) {
        return workflowService.streamWorkflow(request.getWorkflowID(), request.getParameters());
    }

    /**
     * 工作流请求模型
     */
    public static class WorkflowRequest {
        private String workflowID;
        private Map<String, Object> parameters;

        // 构造函数
        public WorkflowRequest() {
        }

        public WorkflowRequest(String workflowID, Map<String, Object> parameters) {
            this.workflowID = workflowID;
            this.parameters = parameters;
        }

        // Getter和Setter方法
        public String getWorkflowID() {
            return workflowID;
        }

        public void setWorkflowID(String workflowID) {
            this.workflowID = workflowID;
        }

        public Map<String, Object> getParameters() {
            return parameters;
        }

        public void setParameters(Map<String, Object> parameters) {
            this.parameters = parameters;
        }
    }
}
